from time import sleep

from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.baidu.com')

driver.find_element_by_link_text('新闻').click()
sleep(2)
hds = driver.window_handles


# 选择新窗口的句柄
driver.switch_to.window(hds[-1])

# 定位，导入元素
driver.find_element_by_link_text('军事').click()
sleep(2)

hds=driver.window_handles

driver.switch_to.window(hds[-1])
# driver.switch_to.window(driver.window_handles[-1])

driver.find_element_by_partial_link_text('英国公布世界').click()

hds=driver.window_handles

driver.switch_to.window(hds[-1])
sleep(2)
driver.close()

hds=driver.window_handles
driver.switch_to.window(hds[-1])
driver.close()

hds=driver.window_handles

driver.switch_to.window(hds[-1])
sleep(2)

driver.find_element_by_id('kw').send_keys('Selenium')
driver.find_element_by_id('su').click()
sleep(2)


driver.quit()


